<%@ page contentType="text/html; charset=UTF-8" %>
<%@page import="cn.bopomo.dealer.base.common.CommonConstant"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<html:html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>权限管理</title>
				<script language="javascript" src="/js/json2.js"></script>
		<script language="javascript" src="/js/litpen_ajax.js"></script>		
		<script language="javascript" type="text/javascript">
			var mid = <%=request.getParameter("mid")%>
			
			/* -----发送AJAX请求_获取模块信息-----*/
			function loadModule(){
				var loadModule_ajax = new Ajax("/admin/loadModuleAjax.do?mid="+mid,null,true,loadModuleCallback,"get");
				loadModule_ajax.send();
			}
			
			/* -----接收AJAX返回信息_获取模块信息-----*/
			function loadModuleCallback(){
				var result = arguments[0];
				//alert(result);
				if (result == "")
					return;
				var myData = JSON.parse(result,null);
				//var moduleId = document.getElementById("moduleId");
				var moduleName = document.getElementById("moduleName");
				//var moduleAction = document.getElementById("moduleAction");
				//var moduleTag = document.getElementById("moduleTag");
				var addDate = document.getElementById("addDate");
				//moduleId.innerText = myData.moduleId;
				moduleName.innerText = myData.moduleName;
				//moduleAction.innerText = myData.moduleAction;
				//moduleTag.innerText = myData.moduleTag;
				addDate.innerText = myData.addDate;
			}
			
			/* -----发送AJAX请求_获取模块权限列表-----*/
			function loadModuleAuthorizeList(){
				var moduleAuthorizeList_ajax = new Ajax("/admin/loadModuleAuthorizeListAjax.do?mid="+mid,null,true,loadModuleAuthorizeListCallback,"get");
				moduleAuthorizeList_ajax.send();
			}
			

			
			/* -----接收AJAX返回信息_获取模块权限列表-----*/
			function loadModuleAuthorizeListCallback(){
				var result = arguments[0];
				//alert(result);
				if (result == ""){
					var authorize_div = document.getElementById("authorizeList");
					authorize_div.innerHTML = "暂时没有权限信息";
					return;
				}
				var myData = JSON.parse(result,null);
				var authorize_div = document.getElementById("authorizeList");
				if (authorize_div){
					authorize_div.innerHTML = "";
					var authorize_table = document.createElement("Table");
					for (var i = 0; i < myData.authorizes.length; i++){
						var row = authorize_table.insertRow();
						if(i%2 == 0){
							row.setAttribute("bgcolor","#EEEEEE");
						}else{
							row.setAttribute("bgcolor","#DDDDDD");
						}
						var cell = row.insertCell();
						cell.innerHTML= myData.authorizes[i].authorizeId;
						cell = row.insertCell();
						cell.innerHTML= myData.authorizes[i].authorizeName;
						cell = row.insertCell();
						cell.innerHTML= '<input type="button" value="编辑" ref="003" onclick="javascript:loadAuthorize(' + myData.authorizes[i].authorizeId + ');"/>'
						cell = row.insertCell();
						cell.innerHTML= '<input type="button" value="删除" ref="004" onclick="javascript:deleteAuthorize(' + myData.authorizes[i].authorizeId + ');"/>'
						
					}
					authorize_div.appendChild(authorize_table);
					initDiv(user_moduleList);
				}
			}
			
			/* -----发送AJAX请求_提交权限(新增/修改)-----*/
			function submitAuthorize(){
				var form = document.getElementById("authorizeInfoForm");
				var submitAuthorize_ajax ;
				if(document.getElementById("authorizeSubmit").innerText == "新增"){
					var axaj_fun_name = "/admin/addAuthorizeToModuleAjax.do";
				}else{
					var axaj_fun_name = "/admin/modifyAuthorizeAjax.do";
				}
				var submitAuthorize_ajax = new Ajax(
										axaj_fun_name,
										formToRequestString(form),
										true,
										submitAuthorizeToModuleCallback,
										"post");
				submitAuthorize_ajax.send();
			}
			
			/* -----接收AJAX返回信息_提交权限-----*/
			function submitAuthorizeToModuleCallback(){
				var result = arguments[0];
				var values = result.split("||");
				alert(values[1]);
				if(values[0] == "00"){
					loadModuleAuthorizeList();
				}
			}
						

			/* -----发送AJAX请求_查询权限-----*/
			function loadAuthorize(aid){
				var loadAuthorize_ajax = new Ajax(
									"/admin/loadAuthorizeAjax.do?aid=" + aid,
									null,
									true,
									loadAuthorizeDetailCallback,
									"get");
				loadAuthorize_ajax.send();
			}
			
			/* -----接收AJAX返回信息_查询权限-----*/
			function loadAuthorizeDetailCallback(){
				var result = arguments[0];
				//alert(result);
				if (result == "")
					return;
				var myData = JSON.parse(result,null);
				var authorizeId = document.getElementById("aId");
				var authorizeName = document.getElementById("authorizeName");
				var authorizeAction = document.getElementById("authorizeAction");
				var authorizeTag = document.getElementById("authorizeTag");
				var authorizeAddDate = document.getElementById("authorizeAddDate");
				
				authorizeId.setAttribute("value",myData.authorizeId);
				authorizeName.setAttribute("value",myData.authorizeName);
				authorizeAction.setAttribute("value",myData.authorizeAction);
				authorizeTag.setAttribute("value",myData.authorizeTag);
				authorizeId.setAttribute("value",myData.authorizeId);
				authorizeAddDate.innerText = myData.addDate;
				document.getElementById("authorizeSubmit").innerText = "修改";
				//document.getElementById("authorizeSubmit").onClick = "modifyAuthorizeInfo();";
				document.getElementById("authorizeAddDateDiv").style.display="block";
			}

			
			/* -----发送AJAX请求_删除权限-----*/
			function deleteAuthorize(aid){
				var deleteAuthorize_ajax = new Ajax(
									"/admin/deleteAuthorizeAjax.do?aid=" + aid,
									null,
									true,
									submitAuthorizeToModuleCallback,
									"get");
				deleteAuthorize_ajax.send();
			}
			
			
			/* -----取消按钮-----*/
			function authorizeFormCancel(){
				document.getElementById("aId").value="";
				document.getElementById("authorizeName").value="";
				document.getElementById("authorizeAction").value="";
				document.getElementById("authorizeTag").value="";
				document.getElementById("authorizeAddDate").value="";
				document.getElementById("authorizeSubmit").innerText = "新增";
				document.getElementById("authorizeSubmit").onClick = "addAuthorizeToModule();";
				document.getElementById("authorizeAddDateDiv").style.display="none";
			}
		</script>
	</head>                                                                                                                                                        
	<body>
		<TABLE width="95%" align="center" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF" style="border:1px solid #56626d;font-size:12px">
		  <TR bgcolor="#FFFFFF">
		    <TD colspan="3" align="left" style="font-size:14px"><B>&nbsp;&nbsp;权限管理</B></TD>
		  </TR>
		  <TR bgcolor="#FFFFFF">
		    <TD style="background:#46525d;text-align: center;">
		    	<span style="background:#46525d;color:#FFFFFF;text-align: center;">
					<div id="moduleName"></div>
				</span>
			</TD>
		  </TR>
		  <TR bgcolor="#EEEEEE">
		    <TD nowrap align="center">
				创建日期: <span id="addDate">正在加载数据......</span>
			</TD>
		  </TR>
		  <TR bgcolor="#EEEEEE">
		    <TD nowrap align="center">
		    	<div id="authorizeInfo" ref="002">
					<table>
						<tr>
							<td>
								<html:form method="POST" styleId="authorizeInfoForm" action="/admin/addAuthorizeToModuleAjax.do">
									<html:hidden property="moduleRef" value="<%=request.getParameter("mid")%>"/>
									<html:hidden property="aid" value=""/>
									权限名称:<html:text property="authorizeName"/><br/>
									权限动作:<html:text property="authorizeAction"/><br/>
									权限标识:<html:text property="authorizeTag"/><br/>
									<span id="authorizeAddDateDiv" style="display:none; ">
									创建日期:<span id="authorizeAddDate"></span></span>
									<button onClick="submitAuthorize();" id="authorizeSubmit">新增</button>
									<button onClick="authorizeFormCancel();" id="authorizeCancel">取消</button>
								</html:form>
							</td>
						</tr>
					</table>
		    	</div>
			</TD>
		  </TR>
		  <TR bgcolor="#EEEEEE">
		    <TD nowrap align="center">
		    	<div id="authorizeList">正在加载数据......</div>
			</TD>
		  </TR>
		</TABLE>
		  <script language="javascript" type="text/javascript">
		  	loadModule();
		  	loadModuleAuthorizeList();
		  </script>
		
		
		
	</body>
</html:html>
